//
//  SearchViewController.m
//  FangXinLang
//
//  Created by apple on 16/9/13.
//  Copyright © 2016年 AJY. All rights reserved.
//

#import "SearchViewController.h"
#import "UIBarButtonItem+BarButtonItem.h"

@interface SearchViewController ()<UISearchBarDelegate>

@property (nonatomic,strong) UISearchBar * search;

@end

@implementation SearchViewController
#pragma mark 当视图被驳回时，覆盖或以其他方式隐藏
-(void)viewWillDisappear:(BOOL)animated{
    self.navigationController.navigationBar.subviews.firstObject.alpha = 1;
}
#pragma mark 当视图将要被显示时调用
-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.subviews.firstObject.alpha = 0;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self addItemAndTextField];
    //删除系统自带的Back返回键
    self.navigationItem.hidesBackButton = YES;
    
}
#pragma mrak 添加搜索栏和右边的取消按钮
-(void)addItemAndTextField{
    //添加右边按钮
    UIButton * btnR = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnR setTitle:@"取消" forState:UIControlStateNormal];
    [btnR setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem * itemR = [UIBarButtonItem barButtonItemWith:btnR andTarget:self andAction:@selector(rightBtn) andImage:nil andImageHeight:nil];
    self.navigationItem.rightBarButtonItem = itemR;
    //
    self.search = [[UISearchBar alloc]initWithFrame:CGRectMake(10, 0, 300, 30)];
    self.navigationItem.titleView = self.search;
//    [self.navigationController.navigationBar addSubview:self.search];
}
#pragma mark 右边黑名单按钮监听事件
-(void)rightBtn{
    self.tabBarController.tabBar.hidden = NO;
    
    [self.navigationController popViewControllerAnimated:YES];
}

@end
